<template>
    <div v-loading="loading" class="app-container">
        <!-- 查询条件开始 -->
        <el-card class="cardmargin">
            <el-form ref="queryForm" :model="queryParams" :inline="true" label-width="68px">
                <el-form-item label="选择日期">
                    <el-date-picker v-model="queryParams.dateRange" size="small" value-format="yyyy-MM-dd" type="daterange"
                                    range-separator="-" start-placeholder="开始日期(默认今天)" end-placeholder="结束日期(默认今天)"/>
                </el-form-item>
                <el-form-item>
                    <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
                    <el-button type="primary" icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
                </el-form-item>
            </el-form>
        </el-card>
        <!-- 查询条件结果 -->
        <el-card class="cardmargin">
            合计收入:￥<span>{{ revenueObj.aggregateIncome }}</span>
        </el-card>
        <el-card class="cardmargin">
            收支概况:
            <span class="spancls">总收入￥{{ revenueObj.generalIncome }}</span>
            <span class="spancls spanred">总退费￥{{ revenueObj.totalRefund }}</span>
        </el-card>
        <el-card class="cardmargin">
            收入渠道:
            <span class="spancls">现金支付￥{{ revenueObj.cashPayment }}</span>
            <span class="spancls">支付宝支付￥{{ revenueObj.payAlipay }}</span>
            <span class="spancls spanred">现金退费￥{{ revenueObj.cashRefund }}</span>
            <span class="spancls spanred">支付宝退费￥{{ revenueObj.alipayRefund }}</span>
        </el-card>
        <!-- 图表开始 -->
        <el-card>
            <el-row :gutter="32">
                <el-col :xs="24" :sm="24" :lg="8">
                    <div>
                        <pie-chart ref="p1" :prop-pie-data="revenueOverview"/>
                    </div>
                </el-col>
                <el-col :xs="24" :sm="24" :lg="8">
                    <div>
                        <pie-chart ref="p2" :prop-pie-data="incomeChanel"/>
                    </div>
                </el-col>
                <el-col :xs="24" :sm="24" :lg="8">
                    <div>
                        <pie-chart ref="p3" :prop-pie-data="refund"/>
                    </div>
                </el-col>
            </el-row>
        </el-card>
        <!-- 图表结束 -->
    </div>
</template>

<script>
    import PieChart from './components/PieChart'

    export default {
        name: "revenue",
        components: {
            PieChart
        },
        data() {
            return {
                // 遮罩
                loading: false,
                // 查询参数
                queryParams: {},
                // 数组结构
                revenueObj: {
                    //合计收入
                    aggregateIncome: 0.00,
                    //收支概况: 总收入￥0 总退费￥0
                    generalIncome: 0.00,
                    totalRefund: 0.00,
                    //收入渠道: 现金支付￥0 支付宝支付￥0 现金退费￥0 支付宝退费￥0
                    cashPayment: 0.00,
                    payAlipay: 0.00,
                    cashRefund: 0.00,
                    alipayRefund: 0.0,
                },
                // 声明图表的数据
                revenueOverview: { // 收支概况
                    title: '收支概况',
                    data: [{
                        value: 0,
                        name: '收费金额'
                    },
                        {
                            value: 0,
                            name: '退费金额'
                        }
                    ]
                },
                incomeChanel: { // 收入渠道
                    title: '收入渠道',
                    data: [{
                        value: 0,
                        name: '现金笔数'
                    },
                        {
                            value: 0,
                            name: '支付宝笔数'
                        }
                    ]
                },
                refund: { // 退款金额和渠道
                    title: '退款',
                    data: [{
                        value: 0,
                        name: '现金退费'
                    },
                        {
                            value: 0,
                            name: '支付宝退费'
                        }
                    ]
                }
            }
        },
        created() {
            this.loadData()
        },
        methods: {
            // 查询数据
            loadData() {
                this.loading = true
                this.$axios.post("statistics/api/order-charge/getInfo", this.queryParams).then(res => {
                    this.revenueObj = res.data.data;

                    let revenueOverview = {
                        title: '收支概况',
                        data: [{
                            value: res.data.data.generalIncome,
                            name: '收费金额'
                        },
                            {
                                value: res.data.data.totalRefund,
                                name: '退费金额'
                            }
                        ]
                    }
                    let incomeChanel = {
                        title: '收入渠道',
                        data: [{
                            value: res.data.data.numCashPayment,
                            name: '现金笔数'
                        },
                            {
                                value: res.data.data.numPayAlipay,
                                name: '支付宝笔数'
                            }
                        ]
                    }
                    let refund = {
                        title: '退款',
                        data: [{
                            value: res.data.data.cashRefund,
                            name: '现金退费'
                        },
                            {
                                value: res.data.data.alipayRefund,
                                name: '支付宝退费'
                            }
                        ]
                    }
                    this.revenueOverview = revenueOverview;
                    this.incomeChanel = incomeChanel;
                    this.refund = refund;
                    this.loading = false
                }).catch(() => {
                    this.msgError('查询失败')
                    this.loading = false
                })
            },
            // 条件查询
            handleQuery() {
                this.loadData()
            },
            // 重置查询条件
            resetQuery() {
                this.queryParams = {}
                this.loadData()
            }
        }
    }
</script>

<style scoped>
    .cardmargin {
        margin-bottom: 3px;
    }

    .spancls {
        display: inline-block;
        margin-left: 80px;
    }

    .spanred {
        color: red;
    }
</style>